//
//  TMNearbyBusinessController.m
//  国学商家管理
//
//  Created by Tao Li on 2018/7/4.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMNearbyBusinessController.h"
#import "TMNearbyBussinessCell.h"
#import "TMShopHomeController.h"
@interface TMNearbyBusinessController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *businessCollection;
@property (nonatomic, assign) CGSize itemSize;
@end

@implementation TMNearbyBusinessController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"附近商家";
}
- (void)setBusinessCollection:(UICollectionView *)businessCollection{
    _businessCollection = businessCollection;
    [_businessCollection registerNib:[UINib nibWithNibName:@"TMNearbyBussinessCell" bundle:nil] forCellWithReuseIdentifier:@"TMNearbyBussinessCell"];
    _businessCollection.delegate = self;
    _businessCollection.dataSource = self;
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumLineSpacing = 12;
    flowLayout.minimumInteritemSpacing = 0;
    _itemSize = CGSizeMake(174 * kWindowW /375, 240* kWindowW /375);
    _businessCollection.collectionViewLayout = flowLayout;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return self.itemSize;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(12, 12, 0, 12);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TMNearbyBussinessCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TMNearbyBussinessCell" forIndexPath:indexPath];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    TMShopHomeController *vc = [[UIStoryboard storyboardWithName:@"Nearby" bundle:nil] instantiateViewControllerWithIdentifier:@"TMShopHomeController"];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
